package com.tianqi.familymap.entry

import android.os.Bundle
import com.google.android.material.tabs.TabLayoutMediator
import com.jaeger.library.StatusBarUtil
import com.tianqi.familymap.R
import com.tianqi.familymap.adapter.SimpleAdapter
import com.tianqi.familymap.base.BaseActivity
import com.tianqi.familymap.base.BaseFragment
import com.tianqi.familymap.fragment.FirstFragment
import com.tianqi.familymap.fragment.InformationFragment
import com.tianqi.familymap.fragment.MyFragment
import com.tianqi.familymap.fragment.SecondFragment
import com.tianqi.familymap.utils.AppManager
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : BaseActivity() {
    private val mTablaHome by lazy { tablayout_home }
    private val mViewpagerHome by lazy { viewpager_home }
    private val mAppManager by lazy {
        AppManager.get()
    }
    private val mlist = ArrayList<BaseFragment>()
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        initView()
    }

    private fun initView(){
        mAppManager.addActivity(this)
        val firstFragment = FirstFragment()
        val secondFragment = SecondFragment()
        val informationFragment = InformationFragment()
        val myFragment = MyFragment()
        mlist.add(firstFragment)
        mlist.add(secondFragment)
        mlist.add(informationFragment)
        mlist.add(myFragment)
        val simpleAdapter = SimpleAdapter(this, mlist)
        mViewpagerHome.adapter = simpleAdapter

        val title = ArrayList<String>()
        title.add("故事")
        title.add("友品")
        title.add("消息")
        title.add("我的")
        TabLayoutMediator(mTablaHome, mViewpagerHome) { tab, position ->
            tab.text = title[position]
        }.attach()
    }

    override fun setStatusBar() {
        StatusBarUtil.setTranslucentForImageViewInFragment(this,0,null)
    }

    override fun onDestroy() {
        super.onDestroy()
        mAppManager.finishActivity(this)
    }
}